package servlet.other;

import entity.other.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * DBUtils执行数据库查询操作
 * 1.QueryRunner(DataSource)
 * 2.query(String sql, ResultSetHandler<T> rsh, Object... params); // 主要执行查询
 */

public class DBUtilsDemo {
    public static void main(String[] args) throws SQLException {
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai", "root", "123456");
        QueryRunner queryRunner = new QueryRunner();
        queryRunner.query(connection, "select * from user", new BeanListHandler<>(User.class));
        connection.close();
    }
}